# Contributor: Alexander Georgievskiy <galeksandrp@gmail.com>
# Contributor: Andrew Sun <adsun701@gmail.com>

_realname=fdk-aac
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.1
pkgrel=1
pkgdesc="A standalone library of the Fraunhofer FDK AAC code from Android (mingw-w64)"
arch=('any')
license=('custom')
makedepends=('autoconf' 'automake' 'libtool' 'make')
url="https://github.com/mstorsjo/${_realname}"
source=(${_realname}-${pkgver}.tar.gz::"${url}/archive/v${pkgver}.tar.gz")
sha256sums=('a4142815d8d52d0e798212a5adea54ecf42bcd4eec8092b37a8cb615ace91dc6')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  ./autogen.sh
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd ${srcdir}/build-${CARCH}

  make DESTDIR=${pkgdir} install
  
  # Install license
  install -dm 755 "${pkgdir}${MINGW_PREFIX}"/share/licenses/libfdk-aac
  install -m 644 "${srcdir}"/${_realname}-${pkgver}/NOTICE "${pkgdir}${MINGW_PREFIX}"/share/licenses/libfdk-aac/
}
